package mmc.server.shell.ops;

import java.lang.reflect.Field;

import mmc.Settings;
import mmc.server.shell.OperationNotAcceptedException;
import mmc.server.shell.ShellException;
import mmc.server.shell.Util;

public class EngineSetting extends Operation implements Assignable{
	
	private Field field;
	
    public EngineSetting(String text) throws ShellException {
        super(text = text.trim());
        
        try {
            field = Settings.class.getField(text.toUpperCase());
        } catch (Exception e) {
            throw new OperationNotAcceptedException(false, "No value: " + e.getMessage());
        }
    }
    
    @Override
    public double execute() {
    	return Util.getField(field, null);
    }
    
    @Override
    public void set(Object value){
    	Util.setField(field, Util.assignToDouble(value), null);
    }
    
    public static String getDescription(){
    	return formatHelpString("Setting","static field of "+Settings.class.getName());
    }
    
    public static PriorityType getPriorityType() {
        return PriorityType.VARIABLE;
    }
}
